<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/js/base-loading.js"></script>
<title>项目管理</title>
</head>
<style>
.search-input.clear{height:30px;line-height: 30px;}
</style>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="../app/index.do"></a>
			</div>
			<div class="header-title">项目列表</div>
		</div>
	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<table id="pro_table" class="easyui-datagrid" style="min-height: 100%">
			</table>
			<div id="pro_tb" class="search-show">
				<div class="search-input clear">
					<span class="fl">发布日期：</span>
					<span class="dates">
						<span><input id="fromDate" class="easyui-datebox" editable="false" style="width: 100%;" /></span>
						<span>~</span>
						<span><input id="toDate" class="easyui-datebox" editable="false" style="width: 100%;" /></span>
					</span>
				</div>
				<div class="search-input text-right">
				<a href="#" class="d-btn btn-yellow"  id="search">搜索</a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	var currentPro;
	var currentChild;
	var fromDate = "";
	var toDate = "";
	$(document).ready(function() {
		fromDate = getLastMonth().last;
		toDate = getLastMonth().now;
		$("#fromDate").datebox('setValue', fromDate);
		$("#toDate").datebox('setValue', toDate);
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			url : "../level2/projectitems.do",
			method : 'get',
			queryParams : {
				startdate : fromDate,
				enddate : toDate
			},
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'name',
				title : '项目名',
				width : '100%;',
				formatter : function(value,row,index) {
					var html = '';
					html += '<div class="info info-mypro"><div class="info-item-name" style="width:'+ ellipsis(60) +'px;margin-bottom:10px;">' + row.projectno
							+ '</div><div class="info-item-content" style="width:'+ ellipsis(0) +'px;">' + row.name + '</div>';
					
					html += '<div class="info-content">' + row.projectaddr
							+ '</div>'
							html += '<div class="info-time"><span>该项目从' + formatDate(row.startdate) + '起</span>'
							html += '<span>至' + formatDate(row.enddate) + '结束</span></div>'
							html+='<div class="info-time info-time-fb">'
					if (row.creater){
						html += '<span>' + row.creater.name + '</span>';
					}else{
						html;
					}
					html += '<span>发布于' + formatDate(row.createdate) + '</span></div>';
					if (row.status == 1){
						html += '<div class="info-status two">待确认<a href="javascript:void(0)" class="editcls d-btn btn-green"  onclick="confirm('
							+ row.id + ')">确认 </a></div>';
					}
					if (row.status == 2){
						html += '<div class="info-status green">进行中</div>';
					}
					if (row.status == 3){
						html += '<div class="info-status refuse">废止</div>';
					}
					if (row.status == 5){
						html += '<div class="info-status ok">结束</div>';
					}
					html += '<div class="edit"><span class="info-more" onclick="addTab(' + index
					+ ')"></span><span class="info-edit" onclick="updatepro(' + index
							+ ')"></span></div></div>';
					return html;
				}
			} ] ]
		});
	});
	function ellipsis(value){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-value
		return width;
	}
	function addTab(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		window.location.href = "../app/tochild.do?projectitemid=" + item.id;
	}
	function refreshProTable() {
		$('#pro_table').datagrid("load", {
			startdate : fromDate,
			enddate : toDate
		});
	}
	function updatepro(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		window.location.href = "../app/projectitemadd2.do?id=" + item.id;
	}
	$("#search").click(function() {
		fromDate = $("#fromDate").datebox('getValue');
		toDate = $("#toDate").datebox('getValue');
		refreshProTable();
	});
	function confirm(id) {
		$.ajax({
			type : 'POST',
			url : "../ProjectItemConfirm.do?id=" + id,
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.alert('确认', '确认成功', 'success');
					refreshProTable();
				}else{
					$.messager.alert('确认', '确认失败', 'error');
				}
			},
			dataType : "json"
		});
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(),month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(),hour = date.getHours(),min = date.getMinutes(),sec = date.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	function getLastMonth() {
		var now = new Date();
		var year = now.getFullYear();
		var month = now.getMonth() + 1;//0-11表示1-12月
		var day = now.getDate() + 1;
		var dateObj = {};
		dateObj.now = year + '-' + month + '-' + day;
		var nowMonthDay = new Date(year, month, 0).getDate(); //当前月的总天数
		if (month - 1 <= 0){ //如果是1月，年数往前推一年<br>　　　　 
			dateObj.last = (year - 1) + '-' + 12 + '-' + day;
		}else{
			var lastMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();
			if (lastMonthDay < day){ //1个月前所在月的总天数小于现在的天日期
				if (day < nowMonthDay){ //当前天日期小于当前月总天数
					dateObj.last = year + '-' + (month - 1) + '-' + (lastMonthDay - (nowMonthDay - day));
				}else{
					dateObj.last = year + '-' + (month - 1) + '-' + lastMonthDay;
				}
			}else{
				dateObj.last = year + '-' + (month - 1) + '-' + day;
			}
		}
		return dateObj;
	}
</script>

</html>